import request from '@/utils/request'
import type {
  PostLogin,
  ResApi,
  LoginRes,
  UserListType,
  UserRes,
  AddUserType,
  AssignRoleType,
} from '@/types/user'

// 登录请求
export const loginApi = (data: PostLogin) => {
  return request<ResApi<LoginRes>>({
    method: 'post',
    url: '/user/login',
    data,
  })
}
// 获取用户列表
export const getUserListApi = (params: UserListType) => {
  return request<ResApi<UserRes[]>>({
    method: 'get',
    url: '/user/index',
    params,
  })
}

// 添加用户
export const getAddUser = (data: AddUserType) => {
  console.log(data)

  // return request<ResApi<null>>({
  //   method: 'post',
  //   url: '/user/create',
  //   data,
  // })

  return request.post('/user/create', data)
}

// 删除用户
export const RemoveUserApi = (params: UserRes) => {
  return request<ResApi<null>>({
    method: 'delete', //相对于get参数是拼接到url的后面的
    url: '/user/delete',
    params,
  })
}
// 更新用户
export const updateUserApi = (data: UserRes) => {
  return request<ResApi<null>>({
    method: 'put', //相当于get 参数是拼接到url的后面的
    url: '/user/update',
    data,
  })
}
// 更新分配用户角色权限
export const assignUserRoleApi = (data: AssignRoleType) => {
  return request({
    method: 'put',
    url: '/user/assign',
    data,
  })
}
